package com.qianchang.microfinance.view.mine;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.TradRecordBean;
import com.qianchang.microfinance.view.base.BaseRecyclerAdapter;
import com.dm.library.utils.FormatUtil;
import com.dm.library.widgets.element.DTextView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by jinbailiang on 2017/8/28.
 */

public class TradRecordAdapter extends BaseRecyclerAdapter<TradRecordBean> {


    public TradRecordAdapter(Context context) {
        super(context, BaseRecyclerAdapter.ONLY_FOOTER);
    }

    @Override
    protected MyViewHolder onCreateDefaultViewHolder(ViewGroup parent, int type) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_trad_record, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    protected void onBindDefaultViewHolder(RecyclerView.ViewHolder holder, final TradRecordBean item, final int position) {
        MyViewHolder vh = (MyViewHolder) holder;
        //收入支出类型：
        if ("0".equals(item.getType())) {
            //0.收入
            vh.tvAmount.setText(String.format("+%s", FormatUtil.numKbPointFormat(item.getAmountIn())));
        } else if ("1".equals(item.getType())) {
            //1.支出
            vh.tvAmount.setText(String.format("-%s", FormatUtil.numKbPointFormat(item.getAmountOut())));
        }
        vh.tvType.setText(item.getTradeName());
        vh.tvTime.setText(item.getCreateTime());

    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_type)
        DTextView tvType;
        @BindView(R.id.tv_time)
        DTextView tvTime;
        @BindView(R.id.tv_amount)
        DTextView tvAmount;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }


}
